#/bin/bash

#  rpm -q $package || yum -y install $package
#  还没有完成

rpm -q epel-release || yum -y install  https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-6.noarch.rpm  
rpm -q icinga-rpm-release || yum -y install  https://packages.icinga.org/epel/7/release/noarch/icinga-rpm-release-7-1.el7.centos.noarch.rpm  


Packages="icinga2
nagios-plugins-all
mariadb-server mariadb
icinga2-ido-mysql 
icingaweb2 icingacli
vim-enhanced"

for package in $Packages; do
    rpm -q $package || yum -y install $package
done

# yum install icinga2 nagios-plugins-all
systemctl enable icinga2 
systemctl start icinga2 

[ -f /usr/lib64/nagios/plugins/check_http ] && echo "install nagios-plugins success." || {
    echo "install nagios-plugins failed"
    exit 1
}


# yum install mariadb-server mariadb
vi /etc/my.cnf.d/server.cnf  
systemctl enable mariadb 
systemctl start mariadb 


# yum install icinga2-ido-mysql 
# yum install icingaweb2 icingacli

vim ../conf/httpd.conf  
vim /etc/php.ini  
httpd -t  

systemctl enable httpd 
systemctl start httpd 


usermod -a -G icingaweb2


# yum -y install vim-enhanced
PREFIX=~/.vim   
mkdir -p $PREFIX/{syntax,ftdetect} 
find / -name icinga2.vim
cd /usr/share/doc/icinga2-common-2.4.10/syntax/  
cp vim/syntax/icinga2.vim $PREFIX/syntax/ 
cp vim/ftdetect/icinga2.vim $PREFIX/ftdetect/ 


vim /etc/icingaweb2/resources.ini  
vim /etc/icingaweb2/config.ini  
vim /etc/icingaweb2/authentication.ini  
vim /etc/icingaweb2/roles.ini  

IMM_dir=/etc/icingaweb2/modules/monitoring
[ -d $IMM_dir ] || mkdir -p $IMM_dir
vim /etc/icingaweb2/modules/monitoring/config.ini  
vim /etc/icingaweb2/modules/monitoring/backends.ini  
vim /etc/icingaweb2/modules/monitoring/commandtransports.ini  


mysql -u root icinga2db < /usr/share/icinga2-ido-mysql/schema/mysql.sql
mysql -u root icingaweb2db < /usr/share/doc/icingaweb2/schema/mysql.schema.sql


icinga2 feature enable ido-mysql
icinga2 feature enable command